<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="900px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <!-- <el-col :span="12">
          <el-form-item label="部门名称" prop="deptname">
            <el-input v-model="model.deptname"></el-input>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="12">
          <el-form-item label="项目类型" prop="projecttype" :rules="rules.validateRequire">
            <el-select v-model="model.projecttype" filterable clearable>
              <el-option v-for="item in codeModel.projecttypeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :span="12">
          <el-form-item label="项目等级" prop="projectlevel" :rules="rules.validateRequire">
            <el-select v-model="model.projectlevel" filterable clearable multiple>
              <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="审批人" prop="username" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.usercode" :initDisplayData.sync="model.username" :disabled="false" :singleSelect="true" @confirm="userConfirm" dataType="code"></tl-ref-user>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="工号" prop="usercode">
            <el-input v-model="model.usercode" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="决策部门" prop="deptname" :rules="rules.validateRequire">
            <el-input v-model="model.deptname" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" maxlength="1000" show-word-limit :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: '部门审批人资源池',
      urlPrefix: '/mpm/projectResourcePool/',
      url: {
        // 额外的url
      }
    }
  },
  methods: {
    assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'projecttype', '0')
      }
    },
    userConfirm(selectData) {
      var nameList = ""
      var usercodeList = ""
      var deptname = ""
      selectData.forEach(element => {
        const { code, dispdeptid, name, deptid } = element
        nameList += name + ","
        usercodeList += code + ","
        deptname = dispdeptid
      })
      nameList = nameList.substring(0, nameList.lastIndexOf(','))
      usercodeList = usercodeList.substring(0, usercodeList.lastIndexOf(','))
      this.$set(this.model, 'username', nameList)
      this.$set(this.model, 'usercode', usercodeList)
      this.$set(this.model, 'deptname', deptname)
      this.$set(this.model, 'userList', selectData)
    },
    loaded() {
      // 页面加载完毕执行
    }
  }
}
</script>

